package cc.miwuya.complain.service.impl;

import cc.miwuya.complain.domain.Notice;
import cc.miwuya.complain.mapper.NoticeMapper;
import cc.miwuya.complain.service.NoticeService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author 杩烽浘妫灄
 * @description 针对表【notice(公告表)】的数据库操作Service实现
 * @createDate 2024-02-22 20:10:28
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
        implements NoticeService {

    @Override
    public Object getPage(Page page, Long residentialId, String name) {
        Page<Notice> noticePage;
        if (residentialId == null) {
            if (StrUtil.isEmpty(name)) {
                noticePage = page(page, new QueryWrapper<Notice>());
            } else {
                noticePage = page(page, new QueryWrapper<Notice>().like("content", name));
            }
        } else {
            if (StrUtil.isEmpty(name)) {
                noticePage = page(page, new QueryWrapper<Notice>().eq("residential_id", residentialId));
            } else {
                noticePage = page(page, new QueryWrapper<Notice>().eq("residential_id", residentialId).like("content", name));
            }
        }
        return noticePage;
    }
}




